import constants from "@/util/constants";
import router from "@/router";
export default {
  state: {
    token: '',
    card:'',
    chn:'',
    photoURL:'',
    user:''
  },
  mutations: {
    SET_TOKEN(state, token) {
      state.token = token
    },
    SET_CARD(state, card) {
      state.card = card
    },
    SET_CHN(state, chn) {
      state.chn = chn
    },
    SET_PHOTO_URL(state, photoURL) {
      state.photoURL = photoURL
    },
    SET_USER(state, user) {
      state.user = user
    },
    LOGIN_OUT(state){
      const {storageInfo} = constants
      state.token = ''
      state.card = ''
      state.chn = ''
      state.photoURL = ''
      state.user = ''
      sessionStorage.setItem(storageInfo.token,'')
      sessionStorage.setItem(storageInfo.card,'')
      sessionStorage.setItem(storageInfo.chn,'')
      sessionStorage.setItem(storageInfo.photoURL,'')
      const href = window.location.href
      const ref = /^https?:\/{2,}[^\/]+/
      const match = href.match(ref)
      if(!!match){
        const url = match[0]
        window.location.href = url + window.location.pathname
      }
    }
  },
  actions: {
  },
};
